home *** CD-ROM | disk | FTP | other *** search
/ Chip 2003 October / Chip Ekim 2003.iso / prog / code / contr / setup.exe / Disk1 / data1.cab / Configuration_En / Commands / PMContext.js < prev    next >
Encoding:
JavaScript  |  2003-07-18  |  8.4 KB  |  267 lines

  1. //=========================================================================================================
  2. //
  3. // Copyright 2002, 2003 Macromedia, Inc. All rights reserved.
  4. //
  5. // Feature: Paste Fix
  6. // Author:  JDH
  7. // Module:  PMContext.js
  8. // Purpose:    The context object for the Paste Fix pipeline, as well as wrappers for CSS class access.
  9. // Updates:
  10. //    5/17/02 - Started file control
  11. //
  12. //=========================================================================================================
  13.  
  14. function CSSClassCollection()
  15. {
  16.     // Allocate an associate array to hold the classes
  17.     this.classes = new Array();
  18. }
  19.  
  20. CSSClassCollection.prototype.add = CSSClassCollection_add;
  21. CSSClassCollection.prototype.get = CSSClassCollection_get;
  22. CSSClassCollection.prototype.has = CSSClassCollection_has;
  23.  
  24. function CSSClassCollection_add( name, data )
  25. {
  26.     // Coerce the name to lower case and add the data
  27.  
  28.     name = name.toLowerCase();
  29.     this.classes[ name ] = data;
  30. }
  31.  
  32. function CSSClassCollection_get( name )
  33. {
  34.     // Coerce the name to lower caes and return the class definition
  35.  
  36.     name = name.toLowerCase();
  37.     return this.classes[ name ];
  38. }
  39.  
  40. function CSSClassCollection_has( name )
  41. {
  42.     // Coerce the name to lower case and return true if there is a 
  43.     // class definition
  44.  
  45.     name = name.toLowerCase();
  46.     if ( this.classes[ name ] != null )
  47.         return true;
  48.     return false;
  49. }
  50.  
  51.  
  52.  
  53. function CSSReferenceClassCollection()
  54. {
  55.     // Initialize associate array for the class names
  56.  
  57.     this.classes = new Array();
  58. }
  59.  
  60. CSSReferenceClassCollection.prototype.add = CSSReferenceClassCollection_add;
  61. CSSReferenceClassCollection.prototype.get = CSSReferenceClassCollection_get;
  62. CSSReferenceClassCollection.prototype.has = CSSReferenceClassCollection_has;
  63.  
  64. function CSSReferenceClassCollection_add( name )
  65. {
  66.     // Coerce the name to lower case and add a reference to it to the associative
  67.     // array
  68.  
  69.     name = name.toLowerCase();
  70.     this.classes[ name ] = 1;
  71. }
  72.  
  73. function CSSReferenceClassCollection_get( name )
  74. {
  75.     // We shouldn't be trying to get the class definition, since we don't have
  76.     // them for the target document
  77.  
  78.     alert( "CSSReferenceClassCollection.get( " + name + " ) called" );
  79. }
  80.  
  81. function CSSReferenceClassCollection_has( name )
  82. {
  83.     // Coerce the name to lower case and check for it's existince in the array
  84.  
  85.     name = name.toLowerCase();
  86.     if ( this.classes[ name ] != null )
  87.         return true;
  88.     return false;
  89. }
  90.  
  91.  
  92. function JSStringBuffer() { this._text = ""; }
  93.  
  94. JSStringBuffer.prototype.append = JSStringBuffer_append;
  95. JSStringBuffer.prototype.get = JSStringBuffer_get;
  96.  
  97. function JSStringBuffer_get( ) { return this._text; }
  98. function JSStringBuffer_append( str ) { this._text += str; }
  99.  
  100.  
  101.  
  102. function JSDWBuffer() { this._id = dw.createStringBuffer(); }
  103.  
  104. JSDWBuffer.prototype.append = JSDWBuffer_append;
  105. JSDWBuffer.prototype.get = JSDWBuffer_get;
  106.  
  107. function JSDWBuffer_get( ) { return dw.getStringBuffer( this._id ); }
  108. function JSDWBuffer_append( str ) { dw.appendToStringBuffer( this._id, str ); }
  109.  
  110.  
  111.  
  112. function PasteContext( clipDOM, clipCSS, targetDOM, targetCSS, settings )
  113. {
  114.     // Initialize string buffers
  115.     dw.resetStringBuffers();
  116.  
  117.     // Initialize the member variables
  118.  
  119.     // The clipboard and it's current type (assumend to be HTML)
  120.     this.clipDOM                  = clipDOM;
  121.     this.clipText                 = this.clipDOM.documentElement.outerHTML;
  122.     this.contentType              = CONTENT_TYPE_HTML;
  123.     this.originClasses            = clipCSS;
  124.  
  125.     // The target
  126.     this.targetDOM                = targetDOM;
  127.     this.targetClasses            = targetCSS;
  128.  
  129.     // The information about the current application
  130.     this.originApplicationFull    = "";
  131.     this.originApplication        = null;
  132.     this.originApplicationVersion = null;
  133.  
  134.     // The global settings for the handlers
  135.     this.settings                 = settings;
  136.  
  137.     // The debug data
  138.     this.debugData                = new Array();
  139.  
  140.     // The meta tags
  141.     this.metaTags                 = {};
  142. }
  143.  
  144. PasteContext.prototype.updateClipDOM = PasteContext_updateClipDOM;
  145. PasteContext.prototype.getClipDOM = PasteContext_getClipDOM;
  146. PasteContext.prototype.setClipText = PasteContext_setClipText;
  147. PasteContext.prototype.getClipText = PasteContext_getClipText;
  148. PasteContext.prototype.getDebugText = PasteContext_getDebugText;
  149. PasteContext.prototype.getDebugHTML = PasteContext_getDebugHTML;
  150. PasteContext.prototype.getContentType = PasteContext_getContentType;
  151. PasteContext.prototype.getOriginApplicationFull = PasteContext_getOriginApplicationFull;
  152. PasteContext.prototype.getOriginApplication = PasteContext_getOriginApplication;
  153. PasteContext.prototype.getOriginApplicationVersion = PasteContext_getOriginApplicationVersion;
  154. PasteContext.prototype.setOriginApplicationFull = PasteContext_setOriginApplicationFull;
  155. PasteContext.prototype.setOriginApplication = PasteContext_setOriginApplication;
  156. PasteContext.prototype.setOriginApplicationVersion = PasteContext_setOriginApplicationVersion;
  157. PasteContext.prototype.addToDebug = PasteContext_addToDebug;
  158. PasteContext.prototype.debugWarning = PasteContext_debugWarning;
  159. PasteContext.prototype.debugInformation = PasteContext_debugInformation;
  160. PasteContext.prototype.debugCritical = PasteContext_debugCritical;
  161. PasteContext.prototype.getSetting = PasteContext_getSetting;
  162. PasteContext.prototype.settingDefined = PasteContext_settingDefined;
  163. PasteContext.prototype.getOriginClasses = PasteContext_getOriginClasses;
  164. PasteContext.prototype.getTargetClasses = PasteContext_getTargetClasses;
  165. PasteContext.prototype.setMeta = PasteContext_setMeta;
  166. PasteContext.prototype.getMeta = PasteContext_getMeta;
  167. PasteContext.prototype.createStringBuffer = PasteContext_createStringBuffer;
  168.  
  169. function PasteContext_setMeta( key, value ) { this.metaTags[ key ] = value; }
  170.  
  171. function PasteContext_getMeta( key ) { return this.metaTags[ key ]; }
  172.  
  173. function PasteContext_updateClipDOM( )
  174. {
  175.     this.clipDOM.documentElement.outerHTML = this.clipText;
  176. }
  177.  
  178. function PasteContext_getClipDOM( )
  179. {
  180.     this.updateClipDOM();
  181.     return this.clipDOM;
  182. }
  183.  
  184. function PasteContext_setClipText( html )
  185. {
  186.     this.clipText = html;
  187. }
  188.  
  189. function PasteContext_getClipText( )
  190. {
  191.     return this.clipText;
  192. }
  193.  
  194. function PasteContext_getTargetDOM( ) { return this.targetDOM; }
  195.  
  196. function PasteContext_getContentType( ) { return this.contentType; }
  197.  
  198. function PasteContext_getDebugText( )
  199. {
  200.     // Build a text string of the debug data generated during the run
  201.  
  202.     var debugText = "";
  203.  
  204.     for ( var index in this.debugData )
  205.     {
  206.         var item = this.debugData[ index ];
  207.         debugText += item.module + " : " + item.text + "\n";
  208.     }
  209.  
  210.     return debugText;
  211. }
  212.  
  213. function PasteContext_getDebugHTML( )
  214. {
  215.     // Build an HTML table that has the debug data from the current run
  216.  
  217.     var debugText = "<table>";
  218.  
  219.     for ( var index in this.debugData )
  220.     {
  221.         var item = this.debugData[ index ];
  222.         debugText += "<tr><td>" + item.module + "</td><td>" + item.level + "</td><td>" + item.text + "</td></tr>\n";
  223.     }
  224.  
  225.     debugText += "</table>";
  226.  
  227.     return debugText;
  228. }
  229.  
  230. function PasteContext_addToDebug ( level, module, text )
  231. {
  232. //    alert( module + "\n" + text );
  233.     this.debugData.push( { level: level, module: module, text: text } );
  234. }
  235.  
  236. function PasteContext_debugWarning ( module, text ) { this.addToDebug( DEBUG_WARNING, module, text ); }
  237.  
  238. function PasteContext_debugInformation ( module, text ) { this.addToDebug( DEBUG_INFORMATION, module, text ); }
  239.  
  240. function PasteContext_debugCritical ( module, text ) { this.addToDebug( DEBUG_CRITICAL, module, text ); }
  241.  
  242. function PasteContext_getOriginApplicationFull() { return this.originApplicationFull; }
  243.  
  244. function PasteContext_getOriginApplication() { return this.originApplication; }
  245.  
  246. function PasteContext_getOriginApplicationVersion() { return this.originApplicationVersion; }
  247.  
  248. function PasteContext_setOriginApplication( name ) { this.originApplication = name; }
  249.  
  250. function PasteContext_setOriginApplicationVersion( version ) { this.originApplicationVersion = version; }
  251.  
  252. function PasteContext_setOriginApplicationFull( name ) { this.originApplicationFull = name; }
  253.  
  254. function PasteContext_getSetting( name ) { return this.settings[ name ]; }
  255.  
  256. function PasteContext_settingDefined( name ) { return ( this.settings[ name ] != null ) ? true : false; }
  257.  
  258. function PasteContext_getOriginClasses( ) { return this.originClasses; }
  259.  
  260. function PasteContext_getTargetClasses( ) { return this.targetClasses; }
  261.  
  262. function PasteContext_createStringBuffer()
  263. {
  264. //    return new JSStringBuffer();
  265.     return new JSDWBuffer();
  266. }
  267.